// ignore_for_file: file_names

import 'dart:math';

import 'package:flutter/material.dart';

class MyApp14 extends StatelessWidget {
  const MyApp14(
      {super.key,
      this.title = '',
      this.content = '',
      this.textCol = Colors.black,
      this.textSize = 0});

  final String title;
  final String content;
  final Color textCol;
  final double textSize;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.orange,
          toolbarHeight: 100,
          title: Center(
            child: Text(
              '$title ',
              style: const TextStyle(color: Colors.white, fontSize: 50),
            ),
          ),
        ),
        body: const MyContainer(),
      ),
    );
  }
}

Color getRandomColor() {
  Random random = Random();
  return Color.fromRGBO(
      random.nextInt(256), random.nextInt(256), random.nextInt(256), 1.0);
}

class MyContainer extends StatelessWidget {
  const MyContainer({super.key});

  @override
  Widget build(BuildContext context) {
    return CustomScrollView(
      slivers: [
        // 类似于 GridView
        SliverGrid.builder(
            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 3,
                mainAxisSpacing: 5,
                crossAxisSpacing: 5,
                childAspectRatio: 4 / 3),
            itemCount: 6,
            itemBuilder: (context, index) {
              return Container(
                color: getRandomColor(),
                alignment: Alignment.center,
                child: Text('黑马程序员$index'),
              );
            }),
        // 类似于 ListView
        SliverList.builder(
            itemCount: 5,
            itemBuilder: (context, index) {
              return Container(
                color: getRandomColor(),
                height: 200,
                alignment: Alignment.center,
                child: Text('黑马程序员$index'),
              );
            })
      ],
    );
  }
}
